package com.v2future.sjt.collegecheckingattendance.fruit.research;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.v2future.sjt.collegecheckingattendance.R;
import com.v2future.sjt.collegecheckingattendance.fruit.bean.ResearchTypeBean;
import com.v2future.sjt.collegecheckingattendance.utils.WidgetUtil;

import java.util.List;

/**
 * 科研类型列表适配器
 * @author shijianting
 * @time 2016/5/20 13:47
 */
public class ResearchTypeAdapter extends BaseAdapter{

    List<ResearchTypeBean> dataList;
    Context mContext;

    public ResearchTypeAdapter(List<ResearchTypeBean> dataList, Context mContext) {
        this.dataList = dataList;
        this.mContext = mContext;
    }

    @Override
    public int getCount() {
        return dataList.size();
    }

    @Override
    public Object getItem(int position) {
        return dataList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }


    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        ResearchTypeBean bean = dataList.get(position);
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(
                    R.layout.listitem_research_type, null);
            holder = new ViewHolder();
            holder.typeTv = (TextView) convertView.findViewById(R.id.tv_type);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        WidgetUtil.setText(holder.typeTv, bean.getResearchSubjectName());
        return convertView;
    }

    public class ViewHolder {
        TextView typeTv;
    }

}
